﻿namespace ZYCommon
{
    using System;
    using System.Drawing;

    public class TableCell
    {
        private bool bolSelected = false;
        private Color intBackColor = Color.Transparent;
        private CellEditStyleConst intEditStyle = CellEditStyleConst.Default;
        private TableCol myCol;
        private TableRow myRow;
        public TableControl myTable = null;
        private object objSelectedObject = null;
        private string strText = null;
        public object Tag = null;

        public Color BackColor
        {
            get
            {
                Color intBackColor = this.intBackColor;
                if (intBackColor.Equals(Color.Transparent))
                {
                    intBackColor = this.myRow.BackColor;
                }
                if (intBackColor.Equals(Color.Transparent))
                {
                    intBackColor = this.myTable.BackColor;
                }
                return intBackColor;
            }
            set
            {
                this.intBackColor = value;
            }
        }

        public Rectangle Bounds
        {
            get
            {
                return new Rectangle(this.myCol.Left, this.myRow.Top, this.myCol.Width, this.myRow.Height);
            }
        }

        public Rectangle ButtonBounds
        {
            get
            {
                int width = 0x10;
                if (width > (this.myRow.Height - 3))
                {
                    width = this.myRow.Height - 3;
                }
                return new Rectangle(this.myCol.Right - width, (this.myRow.Top + 1) + ((this.myRow.Height - width) / 2), width, width);
            }
        }

        public TableCol Col
        {
            get
            {
                return this.myCol;
            }
            set
            {
                this.myCol = value;
            }
        }

        public CellEditStyleConst EditStyle
        {
            get
            {
                CellEditStyleConst intEditStyle = this.intEditStyle;
                if (this.intEditStyle == CellEditStyleConst.Default)
                {
                    this.intEditStyle = this.myCol.EditStyle;
                }
                if (this.intEditStyle == CellEditStyleConst.Default)
                {
                    this.intEditStyle = this.myTable.EditStyle;
                }
                return this.intEditStyle;
            }
            set
            {
                this.intEditStyle = value;
            }
        }

        public int Height
        {
            get
            {
                return this.myRow.Height;
            }
            set
            {
                this.myRow.Height = value;
            }
        }

        public int Left
        {
            get
            {
                return this.myCol.Left;
            }
        }

        public TableRow Row
        {
            get
            {
                return this.myRow;
            }
            set
            {
                this.myRow = value;
            }
        }

        public bool Selected
        {
            get
            {
                return this.bolSelected;
            }
            set
            {
                this.bolSelected = value;
            }
        }

        public object SelectedObject
        {
            get
            {
                return this.objSelectedObject;
            }
            set
            {
                this.objSelectedObject = value;
            }
        }

        public TableControl Table
        {
            get
            {
                return this.myTable;
            }
            set
            {
                this.myTable = value;
            }
        }

        public string Text
        {
            get
            {
                return this.strText;
            }
            set
            {
                this.strText = value;
            }
        }

        public int Top
        {
            get
            {
                return this.myRow.Top;
            }
        }

        public int Width
        {
            get
            {
                return this.myCol.Width;
            }
            set
            {
                this.myCol.Width = value;
            }
        }
    }
}

